package cc.mrbird.assets.service.impl;

import cc.mrbird.assets.domain.EquipmentModel;
import cc.mrbird.assets.domain.Manufacturers;
import cc.mrbird.assets.service.EquipmentModelService;
import cc.mrbird.assets.service.ManufacturersService;
import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.service.impl.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

@Service("equipmentModelService")
public class EquipmentModelServiceImpl extends BaseService<EquipmentModel> implements EquipmentModelService{
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public List<EquipmentModel> findAllList(EquipmentModel equipmentModel, QueryRequest request) {
        try {
            Example example = new Example(EquipmentModel.class);
            Example.Criteria criteria = example.createCriteria();
            example.setOrderByClause("equipment_model_id");
            return this.selectByExample(example);
        } catch (Exception e) {
            log.error("error", e);
            return new ArrayList<>();
        }
    }

    @Override
    public void add(EquipmentModel equipmentModel) {
        this.save(equipmentModel);
    }

    @Override
    public EquipmentModel findByName(String equipment_model_name) {
        Example example = new Example(EquipmentModel.class);
        example.createCriteria().andCondition("lower(equipment_model_name)=", equipment_model_name.toLowerCase());
        List<EquipmentModel> list = this.selectByExample(example);
        return list.isEmpty() ? null : list.get(0);
    }
}
